﻿-- =========================================================================================================
-- Author:		MICHAEL RITACCO
-- Copyright:	2010 MEKHANO GROUP LLC
-- Version:		09/25/2010 1.0
-- =========================================================================================================
CREATE PROCEDURE [flcr].[api_device_category_sel_lov]
@DEVICE_CATEGORY_ID INT = NULL
,@DEVICE_TYPE INT = NULL
,@DEVICE_TYPE_GROUP INT = NULL

AS
BEGIN TRY
  
	SELECT	A.[DEVICE_CATEGORY_ID] 
			,A.[DEVICE_CATEGORY_NAME]
			,C.[DEVICE_TYPE] 
			,C.[DEVICE_TYPE_NAME]
			,D.[DEVICE_TYPE_GROUP]
			,D.[DEVICE_TYPE_GROUP_NAME] 
	  FROM	[FLCR].[DEVICE_CATEGORY] A
	 INNER JOIN [FLCR].[DEVICE_CATEGORY_TYPE_XREF] B
		ON	A.[DEVICE_CATEGORY_ID] = B.[DEVICE_CATEGORY_ID] 
	 INNER JOIN [FLCR].[DEVICE_TYPE] C
	    ON	B.[DEVICE_TYPE] = C.[DEVICE_TYPE]
	 INNER JOIN [FLCR].[DEVICE_TYPE_GROUP] D
	    ON	C.[DEVICE_TYPE_GROUP] = D.[DEVICE_TYPE_GROUP]
     WHERE	A.[DEVICE_CATEGORY_ID] = COALESCE(@DEVICE_CATEGORY_ID,A.[DEVICE_CATEGORY_ID])
	   AND	C.[DEVICE_TYPE] = COALESCE(@DEVICE_TYPE,C.[DEVICE_TYPE])
	   AND	D.[DEVICE_TYPE_GROUP] = COALESCE(@DEVICE_TYPE_GROUP,D.[DEVICE_TYPE_GROUP])

END TRY
BEGIN CATCH
	EXEC [flcr].[utl_getDBError];
END CATCH
